package com.tianyi.sfzy1.controller;

import com.tianyi.sfzy1.domain.Coursediscussion;
import com.tianyi.sfzy1.service.ConsultantService;
import com.tianyi.sfzy1.service.CoursediscussionService;
import com.tianyi.sfzy1.util.R;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/coursediscussion")

public class CoursediscussionController {
    @Autowired
    private CoursediscussionService coursediscussionService;
    //查询所有
    @GetMapping
    public R findAll() {
        return R.ok( coursediscussionService.findAll());
    }
    //多表查询 课程交流表 会员表findAllcam
    @GetMapping("/findAllcam")
    public R findCourseDiscussionAndMember() {
        return R.ok( coursediscussionService.findCourseDiscussionAndMember());
    }


//    //根据id查询
    @GetMapping("/{id}")
    public R selectByPrimaryKey(@Param("discussionId") Integer discussionId) {
        return R.ok( coursediscussionService.selectByPrimaryKey(discussionId));
    }
    //    public R findConsultantByCondition(@Param("realname") String realname,
//                                       @Param("phone") String phone,
//                                       @Param("gender") String gender,
//                                       @Param("levelId") Integer levelId) {
//        return R.ok(consultantService.findConsultantByCondition( realname, phone, gender, levelId));
//    }
    //添加
    @PostMapping
    public R insert(@RequestBody Coursediscussion record) {
        return R.ok( coursediscussionService.insert(record));
    }

    //修改
    @PutMapping
    public R updateByPrimaryKey(Coursediscussion record) {
        return R.ok( coursediscussionService.updateByPrimaryKey(record));
    }

    //删除
    @DeleteMapping
    public R deleteByPrimaryKey(int discussionId) {
        return R.ok( coursediscussionService.deleteByPrimaryKey(discussionId));
    }

    /**
     *批量删除课程类型
     */

    @DeleteMapping("/deleteselect")
    public R deleteSelect(@RequestBody List<Integer> list){
        System.out.println(list);
        int i=coursediscussionService.deleteSelect(list);
        if (i>0){
            return R.ok(null);
        }
        else {
            return R.fail("删除失败");
        }
    }

}
